/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.vienthonga.product.action;

import com.vienthonga.hibernate.pojo.TProduct;
import com.vienthonga.product.logic.ShowMobilephoneByManyfacturerLogic;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author DoanHa
 */
public class ShowMobilephonetByManufacturerAction extends Action {

    private static final Logger logger = Logger.getLogger(
            ShowMobilephonetByManufacturerAction.class.getName());
    private static final String SUCCESS = "success";
    

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        logger.log(Level.INFO, mapping.getPath());

        //nhan request va lay ra querystring
        String manufacturerID = request.getParameter("S_ID");
        int pageIndex = 1;
        if(request.getParameter("page") != null)
            pageIndex = Integer.parseInt(request.getParameter("page"));
       
        //lay ra tat ca dien thoai cua nha san xuat do
        ShowMobilephoneByManyfacturerLogic logic = new ShowMobilephoneByManyfacturerLogic();
        List<TProduct> mobilePhones = logic.getMobilephoneByManufacturer(manufacturerID,pageIndex);

        
        request.setAttribute("mobilePhones", mobilePhones);
        request.setAttribute("NumberOfPage", logic.caculatePaging(manufacturerID));
        request.setAttribute("S_ID", manufacturerID);
        
        return mapping.findForward(SUCCESS);
    }

}
